import { React, useState } from 'react';
import request from "../../utils/request"
import moment from 'moment'
import {
    Form,
    Input,
    Button,
    Radio,
    Select,
    Cascader,
    DatePicker,
    InputNumber,
    TreeSelect,
    Switch,
    Row,
    Col,
    message
} from 'antd';
function Add() {

    const [form] = Form.useForm()
    console.log(form);
    function onFinish(values) {
        values.birth = moment(values.birth).format('YYYY-MM-DD');
        request.post("/student/add", { values }).then((res) => {
            console.log("res", res);
            if (res.data.code == 200) {
                message.success('学生信息添加成功')
                // form.setFieldsValue('')
                form.resetFields('')
            } else {
                message.success('学生信息添加失败')
            }
        })
    }
    return (
        <>
            <h2 style={{ fontSize: 30, textAlign: 'center' }}>学生信息添加</h2>

            <Form
                labelCol={{
                    span: 8,
                }}
                wrapperCol={{
                    span: 8,
                }}
                form={form}
                onFinish={onFinish}

            >
                <Form.Item label="学号" name="userid" rules={[{ required: true, message: '请输入学号!' }]}>
                    <Input />
                </Form.Item>
                <Form.Item label="姓名" name="username" rules={[{ required: true, message: '请输入姓名!' }]}>
                    <Input />
                </Form.Item>
                <Form.Item label="出生日期" name="birth" rules={[{ required: true, message: '请输入出生年月日!' }]}>
                    <DatePicker />
                </Form.Item>
                <Form.Item label="性别" name="sex">
                    <Select>
                        <Select.Option value="男">男</Select.Option>
                        <Select.Option value="女">女</Select.Option>
                    </Select>
                </Form.Item>
                <Form.Item label="联系电话" name="phone">
                    <Input />
                </Form.Item>
                <Form.Item label="学院" name="college">
                    <Input />
                </Form.Item>
                <Form.Item label="专业" name="major">
                    <Input />
                </Form.Item>
                <Form.Item label="班级" name="garde">
                    <Input />
                </Form.Item>
                <Form.Item label="寝室号" name="dormitory">
                    <Input />
                </Form.Item>
                <Row >
                    <Col span={3} offset={9}>
                        <Form.Item>
                            <Button htmlType="submit">添加</Button>

                        </Form.Item>
                    </Col>
                    <Col span={3} offset={0}>
                        <Form.Item>
                            <Button onClick={() => { form.resetFields('') }} >清空</Button>
                        </Form.Item>
                    </Col>

                </Row>
            </Form>
        </>
    )
}
export default Add